/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jule.clases;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.swing.JComboBox;

/**
 *
 * @author Administrador
 */
public class lo {

    public static Object comboGetSelectedValue(JComboBox combito) {
        return combito.getSelectedItem();
    }

    public static int comboGetSelectedIndex(JComboBox combito) {
        return combito.getSelectedIndex();
    }

    public static void comboSelectIndex(JComboBox combito, int indice) {
        combito.setSelectedIndex(indice);
    }

    public static void comboSelectItem(JComboBox combito, String cadena) {
        for (int i = 0; i < combito.getItemCount(); i++) {
            if (combito.getItemAt(i).equals(cadena)) {
                combito.setSelectedIndex(i);
                return;
            }
        }

    }

    public static void comboSelectObject(JComboBox combito, Object objeto) {

        try {
            for (int i = 0; i < combito.getItemCount(); i++) {
                if (combito.getItemAt(i) == objeto.toString()) {
                    combito.setSelectedIndex(i);
                    return;
                }
            }
        } catch (Exception e) {
        }
   }

    public static void comboFillWithCollection(JComboBox comboBox, Collection choices) {
        Iterator iter = choices.iterator();
        while (iter.hasNext()) {
            comboBox.addItem(iter.next());
        }
    }

    private void fillComboWithSet(JComboBox comboBox, Set names) {
        if (comboBox.getItemCount() != 0) {
            comboBox.removeAllItems();
        }
        List nameList = new ArrayList(names);
        Collections.sort(nameList);
        Iterator iterator = nameList.iterator();
        while (iterator.hasNext()) {
            comboBox.addItem(iterator.next());
        }
        nameList.clear();
    }    //    ArrayList getAllItems(JComboBox comboBox) {
//        ArrayList items = new ArrayList(comboBox.getItemCount());
//        for (int i = 0; i < comboBox.getitemcount(); i++) {
//            items.set(i, comboBox.getitemat(i));
//        }
//        return items;
//    }
//
//    ArrayList getAllItems(JComboBox comboBox) {
//        ArrayList items =new ArrayList(comboBox.getItemCount());
//        for (int i =  0; i < comboBox.getitemcount(); i++) {
//            items.set(i, comboBox.getitemat(i));
//        }
//        return items;
//    }
}
